package com.bobi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * swagger3.0的配置类
 */
@Configuration //告知spring当前类是一个配置类，当服务器启动的时候会自动加载该类到内存中
@EnableOpenApi //告知当前类是swagger3的配置文件
public class SwaggerConfig {
    @Bean //告知spring当前方法是一个工厂Bean
    public Docket docket() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo()).enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.bobi"))
                .paths(PathSelectors.ant("/**"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("波比小队-宜人超市后台管理系统-销售管理查询接口文档")
                // 2.返回工具类
                // 2.1 响应状态码的配置
                // 2.2 响应主体的配置
                .description("波比小队制作")
                .contact(new Contact("波 比", "http://www.baidu.com", "123456@qq.com")).version("1.0").build();
    }
}